import 'thinkjs3-ts';
import path from 'path';
import nunjucks from 'think-view-nunjucks';
import fileSession from 'think-session-file';
import fileCache from 'think-cache-file';
import mysql from 'think-model-mysql';
import {Console, File, DateFile} from 'think-logger3'

const isDev = think.env === 'development';
export const cache  = {
  type: 'file',
  common: {
    timeout: 24 * 60 * 60 * 1000 // millisecond
  },
  file: {
    handle: fileCache,
    cachePath: path.join(think.ROOT_PATH, 'runtime/cache'), // absoulte path is necessarily required
    pathDepth: 1,
    gcInterval: 24 * 60 * 60 * 1000 // gc interval
  }
};

export const session = {
  type: 'file',
  common: {
    cookie: {
      name: 'thinkjs'
      // keys: ['werwer', 'werwer'],
      // signed: true
    }
  },
  file: {
    handle: fileSession,
    sessionPath: path.join(think.ROOT_PATH, 'runtime/session')
  }
};

export const view = {
  type: 'nunjucks',
  common: {
    viewPath: path.join(think.ROOT_PATH, 'view'),
    sep: '_',
    extname: '.html'
  },
  nunjucks: {
    handle: nunjucks
  }
};
export const model= {
  type: 'mysql',
  common: {
    logConnect: isDev,
    logSql: isDev,
    logger: (msg: string) => think.logger.info(msg)
  },
  mysql: {
    handle: mysql,
    database: 'thinkjs',
    prefix: 'think_',
    encoding: 'utf8',
    host: '127.0.0.1',
    port: '3306',
    user: 'thinkjs',
    password: '123456',
    dateStrings: true
  }
};

export const logger= {
   type: isDev ? 'console' : 'dateFile',
   console: {
     handle: Console
   },
   file: {
     handle: DateFile,
     backups: 10, // max chunk number
     absolute: true,
     pattern: '-yyyy-MM-dd',
     maxLogSize: 50 * 1024, // 50M
     filename: path.join(think.ROOT_PATH, 'logs/app.log')
   },
   dateFile: {
     handle: DateFile,
     level: 'ALL',
     absolute: true,
     pattern: '-yyyy-MM-dd',
     alwaysIncludePattern: true,
     filename: path.join(think.ROOT_PATH, 'logs/app.log')
   }
};
